<template>
  <div class="real-time-operation">
    <el-form ref="ruleFormRef" :model="ruleForm" label-width="right" class="conditions-form">
      <el-form-item label="省" prop="province">
        <el-select v-model="ruleForm.province" placeholder="请选择省" clearable>
          <el-option label="广东省" value="guangdong"></el-option>
          <el-option label="湖南省" value="hunan"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-select v-model="ruleForm.city" placeholder="请选择市" clearable>
          <el-option label="广州市" value="guangzhou"></el-option>
          <el-option label="深圳市" value="shenzhen"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="区" prop="district">
        <el-select v-model="ruleForm.district" placeholder="请选择区" clearable>
          <el-option label="天河区" value="tianhe"></el-option>
          <el-option label="越秀区" value="yuexiu"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="站点名称" prop="siteName">
        <el-select v-model="ruleForm.siteName" placeholder="请选择站点名称" clearable>
          <el-option label="广州站" value="guangzhou"></el-option>
          <el-option label="深圳站" value="shenzhen"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="投运状态" prop="operationStatus">
        <el-select v-model="ruleForm.operationStatus" placeholder="请选择投运状态" clearable>
          <el-option label="已投运" value="1"></el-option>
          <el-option label="未投运" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm(ruleFormRef)">重置</el-button>
        <el-button type="primary" @click="submitForm(ruleFormRef)">
          查询
        </el-button>
      </el-form-item>
    </el-form>
    <div class="cont">
      <el-table :data="tableData" class="real-table" border @expand-change="handleExpandChange">
        <el-table-column type="expand">
          <template #default="props">
            <div class="details">
              <div class="top">
                <div class="info">
                  <p>站点位置：{{ props.row.siteLocation }}</p>
                  <p>投运时间：{{ props.row.operationTime }}</p>
                  <p>装机功能：{{ props.row.installedFunction }}</p>
                  <p>装机容量：{{ props.row.installedCapacity }}</p>
                </div>
                <el-button>进入监控</el-button>
              </div>
              <div class="content">
                <div class="elQuanCharts">
                  <ECharts :option="props.row?.elQuanOptions" style="width: 100%; height: 100%;" />
                </div>
                <div class="powerCharts"></div>
                <div class="equipmentList"></div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="siteName" label="站点名称" align="center"></el-table-column>
        <el-table-column prop="cloudCommunicationStatus" label="云站通信状态" align="center"></el-table-column>
        <el-table-column prop="pcsWorkStatus" label="PCS工作状态（PCS数量）" align="center" width="200"></el-table-column>
        <el-table-column prop="totalActivePower" label="总有功率" align="center"></el-table-column>
        <el-table-column prop="soc" label="SOC" align="center"></el-table-column>
        <el-table-column prop="todayChargeDischarge" label="今日充/放点量" align="center"></el-table-column>
        <el-table-column prop="airConditionerTemperature" label="空调温度" align="center"></el-table-column>
        <el-table-column prop="liquidCoolingTemperature" label="液冷温度" align="center"></el-table-column>
        <el-table-column prop="currentWarning" label="当前发生警告" align="center"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import ECharts from '@/components/ECharts.vue';
import type { FormInstance } from 'element-plus'

const ruleFormRef = ref<FormInstance>()

const ruleForm = reactive({
  province: '',
  city: '',
  district: '',
  siteName: '',
  operationStatus: ''
})

const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const handleExpandChange = (row: any, expandedRows: any) => {
  console.log(row, expandedRows)
}
const elQuanOptions = ref(
  {
    grid: {
      left: '4%',
      right: '4%',
      top: '20%',
      bottom:'14%'
    },
    legend:{
      data: ['充电量', '放电量', '系统效率'],
      bottom:0,
      right:0
    },
    xAxis: {
      data: ['2024-08-12', '2024-08-13', '2024-08-14', '2024-08-15', '2024-08-16'],
    },
    yAxis: [{
      type: 'value',
      name: '电量/kWh',
      nameTextStyle: {
        color: '#1D2129',
        fontSize: 14
      },
      nameGap: 20,
      axisLabel: {
        color: '#1D2129'
      },
      axisLine: {
        lineStyle: {
          color: '#E5E6EA'
        }
      }
    },
    {
      type: 'value',
      name: '效率 / %',
      position: 'right',
      nameTextStyle: {
        color: '#1D2129',
        fontSize: 14
      },
      nameGap: 20,
      axisLabel: {
        color: '#1D2129'
      },
      axisLine: {
        lineStyle: {
          color: '#E5E6EA'
        }
      },
      axisTick: {
        show: true,
        lineStyle: {
          color: '#E5E6EA'
        }
      },
      splitLine: {
        show: false
      }
    }],
    series: [{
      name: '充电量',
      type: 'bar',
      data: [1500, 2000, 1800, 2500, 2200],
      itemStyle: {
        color: '#43B244',
        borderRadius: [2, 2, 0, 0]
      },
      barWidth: 12,
      barGap: '0%'
    }, {
      name: '放电量',
      type: 'bar',
      data: [1200, 1800, 1600, 2300, 2000],
      itemStyle: {
        color: '#FC7930',
        borderRadius: [2, 2, 0, 0]
      },
      barWidth: 12,
      barGap: '0%'
    }, {
      name: '系统效率',
      type: 'line',
      yAxisIndex: 1, // 使用第二个 yAxis
      data: [80, 85, 182, 88, 186],
      itemStyle: {
        color: '#046AF9'
      },
      symbol: 'circle',
      symbolSize: 12,
      lineStyle: {
        color: '#046AF9',
        width: 2
      },
      areaStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: '#CDE1FE' // 渐变起始颜色
            },
            {
              offset: 1,
              color: 'rgba(230, 240, 254, 0)' // 渐变结束颜色
            }
          ]
        }
      }
    }]
  }
)
//table字段：id、站点名称、云站通信状态、PCS工作状态（PCS数量）、总有功率、SOC、今日充/放点量、空调温度、液冷温度、当前发生警告、站点位置、投运时间、装机功能、装机容量
const tableData = ref([
  {
    id: '1',
    siteName: '广州站',
    cloudCommunicationStatus: '正常',
    pcsWorkStatus: '正常(2)',
    totalActivePower: '1000kW',
    soc: '50%',
    todayChargeDischarge: '100kWh',
    airConditionerTemperature: '25℃',
    liquidCoolingTemperature: '25℃',
    currentWarning: '无',
    siteLocation: '广州市天河区',
    operationTime: '2021-09-01',
    installedFunction: '充电',
    installedCapacity: '1000kW',
    elQuanOptions: elQuanOptions.value
  },
  {
    id: '2',
    siteName: '深圳站',
    cloudCommunicationStatus: '正常',
    pcsWorkStatus: '正常(2)',
    totalActivePower: '1000kW',
    soc: '50%',
    todayChargeDischarge: '100kWh',
    airConditionerTemperature: '25℃',
    liquidCoolingTemperature: '25℃',
    currentWarning: '无',
    siteLocation: '深圳市福田区',
    operationTime: '2021-09-01',
    installedFunction: '充电',
    installedCapacity: '1000kW',
    elQuanOptions: elQuanOptions.value
  }
])
</script>

<style lang="scss" scoped>
.real-time-operation {

  .cont {
    background: #fff;
    padding: 0 0.16rem 0.24rem;

    :deep(.real-table) {
      width: 100%;

      // border: 1px solid #E5E6EA;
      .el-table__expand-icon--expanded {
        color: #046AF9;
      }

      .el-table__expanded-cell {
        background: #F7F8FA;
        padding: 0.2rem 0.4rem;
      }

      .el-table__expanded-cell:hover {
        background: #F7F8FA !important;
      }

      .details {
        .top {
          display: flex;
          justify-content: space-between;
          align-items: center;

          .info {
            display: flex;
            align-items: center;
            width: 15.2rem;
            height: 0.42rem;
            background: #D9F0DA;
            border: 1px solid #B4E0B4;
            font-size: 0.14rem;
            color: #286B29;
            padding: 0 0.24rem;
            font-weight: 500;
            border-radius: 4px;

            p {
              margin-right: 0.66rem;
            }
          }

          .el-button {
            width: 0.88rem;
            height: 0.4rem;
            line-height: 0.4rem;
            font-size: 0.14rem;
            color: #fff;
            border-color: #046AF9;
            background: #046AF9;
            margin-left: 0.2rem;
            border-radius: 4px;
          }
        }

        .content {
          display: flex;
          justify-content: space-between;
          margin-top: 0.12rem;

          .elQuanCharts,
          .powerCharts,
          .equipmentList {
            width: 5.04rem;
            height: 2.6rem;
            background: #fff;
            border-radius: 2px;
          }
        }
      }
    }
  }
}
</style>
